import { BaseWindow } from "../../../component/window/BaseWindow";
import { PageTool } from "../../../common/global/PageTool";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { TilePanel } from "../equipment/TilePanel";
import { FairylandItemShowRenderer } from "./FairylandItemShowRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FairylandTreasureData } from "./FairylandTreasureData";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class FairylandItemShowPanel
    
    export  class FairylandItemShowPanel extends BaseWindow
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 36);
            layer = LayerManager.uiLayer;
            setSize(280, 355);
            title = ObjCreate.createTitleTextField(Language.getString(60107));
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc4=null;
            var loc5=0;
            super.createChildren();
            var loc1=ObjCreate.createBg(17, 40, 245, 250, this, ImagesConst.WindowCenterB);
            var loc2=21;
            var loc3=45;
            loc5 = 0;
            while (loc5 < 36) 
            {
                (loc4 = GlobalClass.getBitmap(ImagesConst.PackItemBg)).x = loc2;
                loc4.y = loc3;
                addChild(loc4);
                if ((loc5 + 1) % 6 != 0) 
                {
                    loc2 = loc2 + 40;
                }
                else 
                {
                    loc2 = 21;
                    loc3 = loc3 + 40;
                }
                ++loc5;
            }
            this._itemListPanel = new TilePanel();
            this._itemListPanel.horizontalGap = 2;
            this._itemListPanel.verticalGap = 2;
            this._itemListPanel.columnWidth = 38;
            this._itemListPanel.rowHeight = 38;
            this._itemListPanel.columnCount = 6;
            this._itemListPanel.rowCount = 6;
            this._itemListPanel.setSize(240, 240);
            this._itemListPanel.setStyle("cellRenderer", FairylandItemShowRenderer);
            this._itemListPanel.move(21, 45);
            addChild(this._itemListPanel);
            this._pagebar = new PageSelecter();
            this._pagebar.mode = PageSelecter.SingleMode;
            this._pagebar.move(90, 297);
            this._pagebar.maxPage = 1;
            this._pagebar.currentPage = 1;
            addChild(this._pagebar);
            this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            var loc6=Language.getString(60108);
            var loc7=ObjCreate.createTextField(loc6, 38, 325, 200, 20, this, GlobalStyle.textFormat1);
            var loc8;
            (loc8 = ObjCreate.createGButton(Language.getString(60109), 190, 295, 70, 23, this, "ButtonYellow")).addEventListener(flash.events.MouseEvent.CLICK, this.onStoreBtnClickHandler);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            if (closeBtn) 
            {
                closeBtn.visible = false;
            }
            return;
        }

        public /* override */ update(arg1: Object, ... rest): void
        {
            var loc1=FairylandTreasureData.treasureInfos;
            this._pageTool.array = loc1;
            if (loc1.length <= 0) 
            {
                this._isClickPage = false;
                this._pagebar.currentPage = 1;
                this._pagebar.maxPage = 1;
            }
            this.updateItemListPanel();
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */=null): void
        {
            this._isClickPage = true;
            this.updateItemListPanel();
            return;
        }

        /* internal  */updateItemListPanel(): void
        {
            var loc1=this._pagebar.currentPage;
            var loc2=this._pageTool.getByPageNo(loc1);
            if (loc2.length >= 36 && !this._isClickPage) 
            {
                loc1 = loc1 + 1;
                loc2 = this._pageTool.getByPageNo(loc1);
            }
            this._pagebar.maxPage = this._pageTool.pagesCount;
            this._pagebar.currentPage = loc1;
            var loc3=new DataProvider(loc2);
            this._itemListPanel.dataProvider = loc3;
            this._itemListPanel.drawNow();
            return;
        }

        protected /* override */ onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        /* internal  */onStoreBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TreasureWareHouseCopyStore));
            return;
        }

        /* internal */ /* var */_itemListPanel: TilePanel;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_isClickPage: Boolean=false;
    }
